<template>
  <a-modal
    :open="open"
    :width="800"
    title="医保目录限价信息查询"
    centered
    :closable="false"
    ok-text="下载"
    :ok-button-props="{ disabled: !isCompleted }"
    @ok="onOk"
    @cancel="onCancel"
  >
    <a-form :model="formState" class="form-style-flex" :label-col="{ style: { width: '160px' } }">
      <a-form-item label="查询日期" class="w-1/2">
        <a-date-picker v-model:value="formState.query_date" class="w-full" placeholder="查询日期" value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="医保目录编码" class="w-1/2">
        <a-input v-model:value="formState.hilist_code" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="医保目录自付比例人员类别" class="w-1/2">
        <SelectItem
          v-model:value="formState.selfpay_prop_psn_type_name"
          type="hilist_lmtpric_type"
          @change="(_, option) => ((formState.selfpay_prop_psn_type = option.value), (formState.selfpay_prop_psn_type_name = option.label))"
        />
      </a-form-item>
      <a-form-item label="目录自付比例类别" class="w-1/2">
        <a-input v-model:value="formState.selfpay_prop_type" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="参保机构医保区划" class="w-1/2">
        <a-input v-model:value="formState.insu_admdvs" placeholder="请输入" />
        <!-- <SelectItem v-model:value="formState.insu_admdvs" type="DT00033" @change="(_, option) => (formState.icd10TypeName = option.label)" /> -->
      </a-form-item>
      <a-form-item label="开始日期" class="w-1/2">
        <a-date-picker v-model:value="formState.begndate" class="w-full" placeholder="开始日期" value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="结束日期" class="w-1/2">
        <a-date-picker v-model:value="formState.enddate" class="w-full" placeholder="结束日期" value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="有效标识" class="w-1/2">
        <a-radio-group v-model:value="formState.vali_flag">
          <a-radio value="">全部</a-radio>
          <a-radio value="1">有效</a-radio>
          <a-radio value="0">无效</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="唯一记录号" class="w-1/2">
        <a-input v-model:value="formState.rid" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="表名" class="w-1/2">
        <a-input v-model:value="formState.tabname" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="统筹区" class="w-1/2">
        <a-input v-model:value="formState.poolarea_no" placeholder="请输入" />
        <!-- <SelectItem v-model:value="formState.poolarea_no" type="DT00033" @change="(_, option) => (formState.icd10TypeName = option.label)" /> -->
      </a-form-item>
      <a-form-item label="更新时间" class="w-1/2" v-bind="validateInfos.updt_time">
        <a-date-picker v-model:value="formState.updt_time" class="w-full" placeholder="更新时间" value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="当前页数" class="w-1/2" v-bind="validateInfos.page_num">
        <a-input v-model:value="formState.page_num" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="本页数据量" class="w-1/2" v-bind="validateInfos.page_size">
        <a-input v-model:value="formState.page_size" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import axios from 'axios'
import { message } from 'ant-design-vue'
// import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
defineProps({
  open: Boolean
  // registerPrice: {
  //   type: Number,
  //   default: () => 0
  // }
})

const formState = ref({
  query_date: '',
  hilist_code: '',
  selfpay_prop_psn_type: '',
  selfpay_prop_type: '',
  insu_admdvs: '',
  begndate: '',
  enddate: '',
  vali_flag: '',
  rid: '',
  tabname: '',
  poolarea_no: '',
  updt_time: '',
  page_num: '',
  page_size: ''
})
const rulesState = ref({
  updt_time: [{ required: true, message: '请选择更新时间' }],
  page_num: [{ required: true, message: '请输入当前页数' }],
  page_size: [{ required: true, message: '请输入本页数据量' }]
})
const { isCompleted, resetFields, validate, validateInfos } = useForm(formState, rulesState)

const onCancel = () => {
  resetFields()
  emit('update:open', false)
}

const onOk = async () => {
  await validate()
  const { code, msg } = await axios.post('/api/v1/insure/downloadybmlxzfblxx', formState.value, {
    headers: { 'Content-Type': 'application/json;charset=UTF-8' }
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  emit('success', [])
}

// watch(
//   () => props.open,
//   (val) => {},
//   { immediate: true }
// )
</script>
<style lang="less" scoped></style>
